<template>
  <div style="padding: 10px 15px">
    <!-- 查询条件-->
    <div class="filter-container">
      <el-button
        class="filter-item seachbttn"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
        >查询</el-button
      >
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-edit"
        @click="handleCreate"
        v-if="Jurisdiction('添加')"
        >新增</el-button
      >
      <el-button
        class="filter-item"
        type="danger"
        icon="el-icon-delete"
        @click="deleteClick()"
        v-if="Jurisdiction('删除')"
        >删除</el-button
      >
    </div>
    <div class="filter_fenge"></div>
    <div class="filter-container">
      <el-button
        class="filter-item bttnleft"
        type="primary"
        icon="el-icon-edit"
        @click="handleCreate"
        v-if="Jurisdiction('添加')"
        >新增</el-button
      >
      <el-button
        class="filter-item"
        type="danger"
        icon="el-icon-delete"
        @click="deleteClick()"
        v-if="Jurisdiction('删除')"
        >删除</el-button
      >
    </div>
    <!--查询条件 end-->

    <!--table-->
    <el-table
      v-loading="listLoading"
      :data="RcnHandRcdData"
      fit
      highlight-current-row
      style="width: 100%"
      stripe
    >
      <el-table-column label="处理人" align="left" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.hndlePrson }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理时间" align="left" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.crtdate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="商户订单编号" align="left" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.merchanNo }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="第三方平台平台订单号"
        align="left"
        min-width="150px"
      >
        <template slot-scope="{ row }">
          <span>{{ row.othNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理描述" align="left" min-width="150px">
        <template slot-scope="{ row }">
          <span>{{ row.dscription }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click="handleClick(scope.row)"
            v-if="Jurisdiction('编辑')"
            type="primary"
            size="mini"
            >编辑</el-button
          >
          <el-button @click="handleClick(scope.row)" type="primary" size="mini"
            >查看详情</el-button
          >
          <el-button
            class="filter-item"
            type="danger"
            icon="el-icon-delete"
            v-if="Jurisdiction('删除')"
            @click="deleteClick()"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="listQuery.total > 0"
      :total="listQuery.total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="fetchData(this)"
    />

    <!--table end -->

    <!--弹出层  新增-->
    <el-dialog title="详情" :visible.sync="dialogFormVisible" width="55%">
      <el-form :model="form" label-position="right">
        <el-form-item label="处理描述">
          <el-input
            type="textarea"
            v-model="form.dscription"
            style="width: 600px"
          ></el-input>
        </el-form-item>
        <el-form-item label="附件列表">
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column
              prop="fileName"
              label="文件名称"
              min-width="280"
            ></el-table-column>
            <el-table-column label="下载地址" min-width="300">
              <template slot-scope="{ row }">
                <a
                  :href="row.attMntPth"
                  target="_blank"
                  title="点击下载"
                  style="text-decoration: underline; color: blue"
                  >{{ row.attMntPth }}</a
                >
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--弹出层 end-->
  </div>
</template>


<script>
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import { AjaxToken, TipConfirm } from "@/api/common";
import { SelectAjax } from "@/api/common";
import { Jurisdiction } from "@/api/common";
import sessionStorage from "@/api/Storage";
import "url-search-params-polyfill"; //兼容IE，否则无法识别URLSearchParams
export default {
  name: "RcnHandRcd",
  components: { Pagination },
  methods: {
    //弹层关闭
    handleClose() {},
    //权限
    Jurisdiction(moduleActionName) {
      return Jurisdiction(moduleActionName, this);
    },
    //多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //多选赋值
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    //搜索
    handleFilter() {
      this.listQuery.page = 1;
      this.fetchData();
    },
    //新增
    handleCreate() {
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.form = {
        iD: "",
        objId: "",
        dscription: "",
        hndlePrson: "",
        crtdate: "",
        cpnId: "",
        handType: "",
        btchId: "",
        merchanNo: "",
        othNo: "",
        attachment: "",
      };
    },
    //编辑
    handleClick(row) {
      this.form.iD = row.iD;
      this.form.objId = row.objId;
      this.form.dscription = row.dscription;
      this.form.hndlePrson = row.hndlePrson;
      this.form.crtdate = row.crtdate;
      this.form.cpnId = row.cpnId;
      this.form.handType = row.handType;
      this.form.btchId = row.btchId;
      this.form.merchanNo = row.merchanNo;
      this.form.othNo = row.othNo;
      this.form.attachment = row.attachment;
      this.dialogStatus = "edit";
      this.dialogFormVisible = true;
      var params = new URLSearchParams();
      params.append("ObjId", row.objId);
      backstage.GetAttchmntRcdLst(this, params);
    },
    //保存
    saveForm() {
      var arr = this.multipleSelection;
      var params = new URLSearchParams();
      params.append("ObjId", this.form.objId);
      params.append("Dscription", this.form.dscription);
      params.append("HndlePrson", this.form.hndlePrson);
      params.append("Crtdate", this.form.crtdate);
      params.append("CpnId", this.form.cpnId);
      params.append("HandType", this.form.handType);
      params.append("BtchId", this.form.btchId);
      params.append("MerchanNo", this.form.merchanNo);
      params.append("OthNo", this.form.othNo);
      params.append("Attachment", this.form.attachment);
      backstage.SaveRcnHandRcd(this, params);
    },
    //删除
    deleteClick(row) {
      var multis = [];
      var params = new URLSearchParams();
      if (row == undefined || row == "") {
        var arr = this.multipleSelection;
        if (arr == undefined || arr.length <= 0) {
          this.$message({
            showClose: true,
            message: "请至少选中一行",
            type: "error",
          });
          this.listLoading = false;
          return;
        } else {
          for (var i = 0; i < arr.length; i++) {
            multis.push(arr[i].id);
          }
          params.append("delds", JSON.stringify(multis));
        }
      } else {
        multis.push(row.id);
        params.append("delds", JSON.stringify(multis));
      }
      this.$confirm("确认删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error",
      })
        .then((a) => {
          this.listLoading = true;
          backstage.DelRcnHandRcd(this, params);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
          this.listLoading = false;
        });
    },
    //查询
    fetchData() {
      this.listLoading = true;
      var params = new URLSearchParams();
      params.append(
        "Parms",
        '{"page":' +
          this.listQuery.page +
          ',"rows":' +
          this.listQuery.limit +
          "}"
      );
      var user = JSON.parse(sessionStorage.getItem("userinfo"));
      // params.append("CpnID",this.form.cpnID == "" ? this.user.cpnId : this.form.cpnID);
      //params.append("AlisNme", this.listQuery.title);
      params.append("CpnID", this.logincpnid);
      params.append("btchid", this.form.btchId);
      backstage.GetRcnHandRcdLst(this, params);
    },
  },
  //初始化
  created() {
    var userinfo = JSON.parse(sessionStorage.getItem("userinfo"));
    this.logincpnid = userinfo.cpnId;
    this.form.btchId =
      this.$route.query.btchid == undefined ? "" : this.$route.query.btchid;
    this.fetchData();
  },
  data() {
    return {
      logincpnid: "",
      tableData: [],
      multipleSelection: [],
      formLabelWidth: "120px",
      RcnHandRcdData: null,
      listQuery: {
        title: "",
        total: 0,
        page: 1,
        limit: 10,
      },
      listLoading: true,
      dialogFormVisible: false,
      dialogdetailsVisible: false,
      dialogStatus: "",
      textMap: {
        update: "修改",
        create: "添加",
      },
      form: {
        iD: "",
        objId: "",
        dscription: "",
        hndlePrson: "",
        crtdate: "",
        cpnId: "",
        handType: "",
        btchId: "",
        merchanNo: "",
        othNo: "",
        attachment: "",
      },
      details_form: {
        iD: "",
        objId: "",
        dscription: "",
        hndlePrson: "",
        crtdate: "",
        cpnId: "",
        handType: "",
        btchId: "",
        merchanNo: "",
        othNo: "",
        attachment: "",
      },
    };
  },
};
//后台事件
var backstage = {
  //获取RcnHandRcd集合
  GetRcnHandRcdLst: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "GetRcnHandRcdLst",
      params,
      "post",
      function (res) {
        thisobj.listLoading = false;
        var body = res.data.data;
        thisobj.RcnHandRcdData = body.rows;
        thisobj.listQuery.page = body.page;
        thisobj.listQuery.total = body.records;
      },
      function (err) {}
    );
  },
  //获取RcnHandRcd集合
  GetAttchmntRcdLst: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "GetAttchmntRcdLst",
      params,
      "post",
      function (res) {
        var body = res.data.data;
        thisobj.tableData = body.rows;
      },
      function (err) {}
    );
  },
  SaveRcnHandRcd: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "SaveRcnHandRcd",
      params,
      "post",
      function (res) {
        var body = res.data;
        if (body.success) {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "success",
            duration: 2000,
          });
          thisobj.fetchData();
          thisobj.dialogFormVisible = false;
        } else {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "error",
          });
        }
      },
      function (err) {}
    );
  },
  DelRcnHandRcd: function (thisobj, params) {
    AjaxToken(
      thisobj,
      "DelRcnHandRcd",
      params,
      "post",
      function (res) {
        thisobj.listLoading = false;
        var body = res.data;
        if (body.success) {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "success",
            duration: 2000,
          });
          thisobj.fetchData();
          thisobj.dialogFormVisible = false;
        } else {
          thisobj.$message({
            showClose: true,
            message: body.message,
            type: "error",
          });
        }
      },
      function (err) {}
    );
  },
};
</script>
